import { _renderPaintInOrder } from '../util/style_class'
import Base from './base_class'

export default class Circle extends Base {
  type = 'Circle'
  angle = 120
  constructor(data: any) {
    super(data)
    for (let key in data) {
      ;(this as any)[key] = (data as any)[key]
    }
  }

  async _render(ctx: any) {
    let w = this.width,
      h = this.height,
      x = this.x + w / 2,
      y = this.y + h / 2,
      piBy2 = Math.PI * this.angle

    ctx.beginPath()
    ctx.save()
    // 用来缩放圆 -- 使其形状变成椭圆
    ctx.scale(1, h / w)
    //  绘制圆形
    ctx.arc(x, y, h, 0, piBy2, false)
    // 用来闭合缺口
    ctx.lineTo(x, y)
    ctx.restore()
    ctx.closePath()

    await this._renderStyle(ctx)
  }
}
